package org.jeecg.modules.demo.sendEmail.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.sendEmail.service.MailPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Tag(name = "邮件发送")
@RestController
@RequestMapping("/sendEmail")
@Slf4j
public class sendEmailController {
    @Autowired
    private MailPushService mailPushService;
    @Operation(summary = "发送邮件", description = "发送邮件")
    @PostMapping("/sendEmail")
    public String sendEmail(String toEmail, String subject, String Content, MultipartFile attachment) throws Exception {
        mailPushService.sendMail(toEmail,subject,Content,attachment);
        return "发送邮件成功";
    }

    @Operation(summary = "给多人发邮件", description = "给多人发邮件")
    @PostMapping("/sendEmailToPersons")
    public String sendEmailToPersons(String toEmail, String subject, String Content, MultipartFile attachment) throws Exception {
        // 使用 split() 方法按逗号分割，并去除多余的空格
        String[] toEmails = toEmail.split("\\s*,\\s*");
        mailPushService.sendMail(toEmails,subject,Content,attachment);
        return "发送邮件成功";
}
}